<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title><?php echo ($name); ?></title>
<script src="__APP__/statics/jquery-1.9.1.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="__APP__/statics/css/jNotify.jquery.css" />
<script type="text/javascript" src="__APP__/statics/jNotify.jquery.js"></script>
<style>
 body{font-family:"微软雅黑";font-size:12px;color:#666666;background-color:#F9F9F6}
 *{margin: 0;} 
 a{text-decoration:none}
 img{border:0px}
.cat{background-color:#F9F9F6;margin-left:10px;z-index:0;}
.cat_list:hover{background-color:#fff;}
.title{background:url("__APP__/statics/tbg.gif");font-weight:bold}

#save{text-align:center;border:0;width:100%;height:40px;background-color:#fff;position:fixed;left:0px;bottom:0px;z-index:999;border:1px solid #DFDFDF;background-color:#DFDFDF;padding:5px;height:20px}
</style>


<div class="cat">
<h2>添加新字段</h2>
<form method="POST" action="__URL__/add_value">
<table id="add_new" border="1" bordercolor="#DDDFFF" width="100%" style="border-collapse: collapse" cellpadding="5">
	<tr>
		<td align="right">模型：</td>
		<td><select size="1" name="model_id">
	<?php if(is_array($model)): $i = 0; $__LIST__ = $model;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$model): $mod = ($i % 2 );++$i; if($model["model_id"] == $choose): ?><option value="<?php echo ($model["model_id"]); ?>" selected><?php echo ($model["model_name"]); ?></option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
	</select>
	</td>
	</tr>
	<tr>
		<td align="right">类型：</td>
		<td>
		<select size="1" name="leixing">
	       <option value="a">文本框</option>
	       <option value="b">下拉框</option>
	</select>
		</td>
	</tr>
	<tr>
		<td align="right">字段名称：</td>
		<td><input type="text" name="value_name" size="20">如：颜色</td>
	</tr>
</table>
<div style="width:200px;margin:0 auto;"><input type="submit" value="添加" name="B1"></div>
</form>
</div>



<div class="cat">
<h2>已添加字段</h2>
<table bordercolor="#DDDFFF" border="1" width="100%" style="border-collapse: collapse" cellpadding="3">
	<tr height="17" align="center">
		<td class="title" width="150">字段</td>
        <td class="title">字段值</td>
		<td class="title" width="40">删除</td>
		
	</tr>
<?php if(is_array($mod_list)): $i = 0; $__LIST__ = $mod_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$mod_list): $mod = ($i % 2 );++$i;?><tr height="20" bgcolor="#F1F5FA" class="cat_list">
		<td width="150">
		<input type="text" name="pdt_id[]" value="<?php echo ($mod_list["id"]); ?>" style="display:none">
		<input type="text" name="pdt_name[]" value="<?php echo ($mod_list["value_name"]); ?>">
		</td>
        <td>
<?php if($mod_list["leixing"] != 'a'): ?><input type="text" name="pdt_value[]" value="<?php echo ($mod_list["pdt_key"]); ?>" size="100">用英文,隔开<?php endif; ?>
		</td>
		<td width="40" align="center"><a href="javascript:;" onclick="del(<?php echo ($mod_list["id"]); ?>)"><img alt="删除" src="__APP__/statics/icons/icon_delete.gif"></a></td>	
	</tr><?php endforeach; endif; else: echo "" ;endif; ?>
</table>
<div id="save"><input id="save_m" type="button" value="保存更改"></div>
</div>



<script>
$(function(){
    $("[name=leixing]").change(function(){
	    var type=$(this).val();
		if(type=='b'||type=='c'){
		   $(".xiala").empty();
		   $("<tr class='xiala'><td align='right'>选择值：</td><td><textarea rows='5' name='value_key' cols='20'></textarea></td></tr>").appendTo($("#add_new"));
	    }else{
		   $(".xiala").empty();
		}
	})

	$("#save").click(function(){
              var pdt_id=[];
			  $("[name='pdt_id[]']").each(function(){pdt_id.push($(this).val());}); 
			   var pdt_name=[];
			  $("[name='pdt_name[]']").each(function(){pdt_name.push($(this).val());}); 
			  var pdt_value=[];
			  $("[name='pdt_value[]']").each(function(){pdt_value.push($(this).val());}); 

			   $.ajax({
			         type:"POST",
					 url:"__URL__/cg_pdt_value",
					 dataType:"html",
					 data:{'pdt_id':pdt_id,'pdt_name':pdt_name,'pdt_value':pdt_value},
					 success:function(data){
						location.reload();
					 }
			   })
	})
})

function del(t){
    var id=t;
	if(confirm('你确认删除此属性吗？')) {
		$.ajax({
			 type:"GET",
			 url:"__URL__/del_pdt",
			 dataType:"json",
			 data:{'id':id},
			 success:function(data){
			 }
		})
		location.reload();
	}
}
</script>